<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="/WEB-INF/tld/fmt.tld"  %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <title></title>
    <base href="<%=basePath%>">
    <%@include file="../common/common.jsp" %>
    <meta charset="UTF-8">
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>
<form class="form-inline definewidth m20" action="stu/queryStu.do" method="post">    
    学号：
    <input type="text" name="stu_no" id="stu_no"class="abc input-default" placeholder="" value="${param.stu_no }">&nbsp;&nbsp;
     姓名：
    <input type="text" name="stu_name" id="stu_name"class="abc input-default" placeholder="" value="${param.stu_name }">&nbsp;&nbsp;    
    <button type="submit" class="btn btn-primary">查询</button>&nbsp;&nbsp; 
    <button type="button" class="btn btn-success" id="btnAdd">新增</button>
</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th>No.</th>
        <th>学号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>生日</th>
        <th>操作</th>
    </tr>
    </thead>
    	<c:forEach var="info" varStatus="i" items="${list }">
			<tr id="tr_${info.id}">
	            <td>${i.count }</td>
	            <td>${info.stu_no }</td>
	            <td>${info.stu_name }</td>
	            <td>
	            	<c:if test="${info.gender eq 1 }">女</c:if>
	            	<c:if test="${info.gender eq 0 }">男</c:if>
	            </td>
	            <td>
	            	${info.birthday }
	            </td>
	            <td>
	                <a href="javascript:void(0)" onclick="edit('${info.id}')">编辑</a>       
	                <a href="javascript:void(0)" onclick="del('${info.id}')">删除</a>
	            </td>
	        </tr>
        </c:forEach>
</table>
</body>
</html>
<script>
    $(function () {
		$('#btnAdd').click(function(){
			window.location.href="stu/studentEdit.jsp?action=add";
		});
    });

	function del(id){
		if(confirm("确定要删除吗？"))
		{
			var url = "index.html";
			window.location.href=url;		
		}
	}
	//修改
	function edit(id){
		window.location.href="stu/queryStuById.do?action=update&id="+id;
	}
	//删除
	function del(id){
		if(!confirm("您确认要删除该学员信息吗,删除后不可恢复?")){
			return;
		}
		$.post("stu/delStu.do",{id:id},function (a,b){
			if(b=='success'){
				var r=a.msg;
				alert(r)
				if(r=='删除成功'){
					var i=a.id;
					$("#tr_"+i).remove();
				}
			}
		})
	}
</script>